<?php
include_once 'head.php';

$pid            = isset( $_GET['id'] )?$_GET['id'] : $_SESSION['pid'] ;
$_SESSION['pid'] = $pid;
print($pid);
$patientHandler = new PatientHandler();
$patient        = $patientHandler->getPatient($pid);

if( $_SERVER['REQUEST_METHOD'] == 'POST'){
    $dobTimeStamp = strtotime($_POST['dob']);
    $patientInfo            = array();
        $patientInfo['fname']   = $_POST['fname'];
        $patientInfo['mname']   = $_POST['mname'];
        $patientInfo['sname']   = $_POST['sname'];
        $patientInfo['sex']     = $_POST['sex'];
        $patientInfo['yy']      = date('y',$dobTimeStamp);
        $patientInfo['mm']      = date('m',$dobTimeStamp);
        $patientInfo['dd']      = date('d',$dobTimeStamp);
        $patientInfo['dob']      = date('Y-m-d',$dobTimeStamp);
        $patientInfo['pid']     =   $pid;
        $patientHandler->updatePatient( $patientInfo );
        header("Location:patient-personal.php");
}



  ?>
<form name="edit-patient" id="edit-patient" method="POST">
<table class="tg">
  <tr><th class="thg">
  <table class="tpt">
    <tr>
      <td><img src= <?php $sex = $patient->sex; if ($sex == 'M'){print "'img/male.gif'";} if ($sex == 'F'){print "'img/female.gif'";} ?> /></td>
      <td class="ptn"><?php echo $patient->firstName; ?></td>
      <td class="ptn"><?php echo $patient->middleName;  ?></td>
      <td class="pto"><?php echo $patient->lastName; ?></td>
      <td class="pto"></td>
        <td class="un"><?php echo $patient->code; ?></td>
      </tr>
    </table>
    </th></tr>
    <tr><td class="tdw">
            
            <div id="tabs_wrapper">
	<div id="tabs_container">
		<ul id="tabs">
			<li class="active"><a href="patient-personal.php">Personal</a></li>
			<li><a  href="patient-gis.php">GIS</a></li>
			<li><a href="patient-growth.php">Growth</a></li>
            <li><a href="patient-immunization.php">Immunization</a></li>
            <li><a href="#tab5">Visits</a></li>
            <li><a href="#tab6">Investigations</a></li>
            <li><a href="#tab7">Imaging</a></li>
            <li><a href="#tab8">Surgical</a></li>
            <li><a href="#tab9">Tretment</a></li>
		</ul>
	</div>
	<div id="tabs_content_container">
		<div id="tab1" class="tab_content" style="display: block;">
			  
    <table><tr><td>
          
            <table cellpadding="7px">
              <tr>
                <td>First Name:<br><input name="fname" type="text"  class="input" value ="<?php echo $patient->firstName; ?>" /> &nbsp; &nbsp;</td>
                <td>Middle Name:<br><input name="mname" type="text"  class="input"  value ="<?php echo $patient->middleName; ?>" /> &nbsp; &nbsp;</td>
                <td>Last Name:<br><input name="sname" type="text"  class="input" value ="<?php echo $patient->lastName; ?>" /> &nbsp; &nbsp;</td>
                <input type="hidden" name="lid" value="<?php echo $patient->pid; ?>">
                <td></td>
              </tr>
              <tr>
                <td>Sex :<br><input name="sex" type="text" class="input" value ="<?php echo $patient->sex; ?>" /> </td>
                <td>Birth date:<br><input name="dob" type="text" class="input" value ="<?php echo $patient->dob; ?>"  /> </td>
                <td>LRH ID:<br /><input name="hid" type="text" class="input"  value ="<?php echo $patient->code; ?>"  /></td>
                <td></td>
              </tr>
              <tr>
                  <td>District:<br><input name="district" class="input"   type="text" value="<?php echo $patient->district; ?>"  /></td>
                  <td>DS / MOH Division:<br><input name="dsd" class="input"   type="text" value="<?php echo $patient->mohDevision; ?>"  /></td>
                  <td>GN Area:<br><input name="gn" class="input"  type="text" value ="<?php echo $patient->gnArea; ?>" ></td>
                  
               </tr>
              <tr>
                <td colspan="3"><table class="ta"><tr><td>Parent/Gardian Name:<br /><select name="ptit"><option value=""></option><option value="Mr." <?php if($patient->gardinTitle=='Mr.'){echo "selected='selected'";} ?> >Mr.</option><option value="Mrs." <?php if($patient->gardinTitle=='Mrs.'){echo "selected='selected'";} ?> >Mrs.</option><option value="Miss." <?php if($patient->gardinTitle=='Miss.'){echo "selected='selected'";} ?> >Miss.</option><option value="Dr." <?php if($patient->gardinTitle=='Dr.'){echo "selected='selected'";} ?> >Dr.</option><option value="Rev." <?php if($patient->gardinTitle=='Rev.'){echo "selected='selected'";} ?> >Rev.</option></select>
                	<br /><input name="pname" type="text" size="25" class="input" value ="<?php echo $patient->gardinName; ?>" /><br />.</td>
                <td>Home Address:<br /><textarea name="addr" rows="2" class="input" cols="28"><?php echo $patient->homeAddress;?></textarea></td></tr></table>
                <td><br /><input type="submit" value="Modify Patient" name="edit" id="edit" class="button" /></td>
              </tr>
              
            </table>
            <br />
        </td></tr></table>
            </form>
        <!--<div id="log">Created by <?php echo $tit." ".$ufname." @ ".$uunit." (".date('Y-m-d',$ct).")"; if ($et != '') { echo ", Last updated by ".$utit." ".$uufname." @ ".$uuunit." (".date('Y-m-d',$et).")"; } ?>.</div> -->
 
		</div>
		
	</div>
</div>
<script>
$(document).ready(function(){
    $("#edit").click(function() {
                 $("#edit-patient").submit(); 
             });
});
  
</script>
  <?php

include_once 'foot.php';
?>